# Comment/uncomment the following line to disable/enable debugging
DEBUG = y

# Ignore signature and/or required kernel key missing - tainting kernel
CONFIG_MODULE_SIG=n

# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2
endif

# For add paramter compile source code, need use ccflags-y, not CFLAGS, EXTRA_FLAGS
ccflags-y += $(DEBFLAGS)
#EXTRA_FLAGS += -I..

ifneq ($(KERNELRELEASE),)
# call from kernel build system

scull-objs := main.o pipe.o
obj-m	:= scull.o

else

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
#KERNELDIR ?= /lib/modules/4.10.0-42-generic/build    #include <asm/uaccess.h> not #include <linux/uaccess.h>
PWD       := $(shell pwd)

default:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif

# For test driver.
test_objects = test.o
ifeq ($(MAKECMDGOALS), test)
	CFLAGS = -g
endif
test: $(test_objects)
	$(CC) -o test $(test_objects)

# phony.
.PHONY: clean

clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c *.order *.symvers .tmp_versions test

depend .depend dep:
	$(CC) $(EXTRA_FLAGS) -M *.c > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif
